package com.Iconcat.system.controller;


import com.Iconcat.system.entity.CatUser;
import com.Iconcat.system.entity.Investment;
import com.Iconcat.system.response.Result;
import com.Iconcat.system.service.InvestmentService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zzq
 * @since 2023-12-19
 */
@RestController
@RequestMapping("/system/investment")
@CrossOrigin
@Api(value = "投资记录模块",tags = "投资记录接口")
public class InvestmentController {
    @Resource
    private InvestmentService investmentService;
    @GetMapping("/all")
    public Result UserAll(@RequestParam(required = true,defaultValue = "1") Integer current,
                          @RequestParam(required = true,defaultValue = "6")Integer size,
                          @RequestParam(required = false)String searchKeyword
    ){
        Page<Investment> page=new Page<>(current,size);
        LambdaQueryWrapper<Investment> queryWrapper=new LambdaQueryWrapper<>();
        // 如果搜索关键字不为空，进行模糊查询
        // 添加条件：如果 searchKeyword 不为空，则添加按照用户账号搜索
        if (StringUtils.isNotBlank(searchKeyword)) {
            queryWrapper.exists("SELECT 1 FROM cat_user cu WHERE cu.userid = user_id AND cu.phone_number LIKE '%" + searchKeyword + "%'");
        }
        IPage<Map<String, Object>> investment=investmentService.selectProjectInvestment(page,queryWrapper);
        return Result.ok().data("data",investment);
    }
}

